<!DOCTYPE html>
<html lang="en">

<head>
	<meta http-equiv="content-type" content="text/html; charset=UTF-8">
	<meta charset="utf-8">
	<title></title>
	<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1, user-scalable=no">
	<meta name="description" content="">
	<meta name="author" content="">
	<!-- STYLESHEETS -->
	<!--[if lt IE 9]><script src="../../js/flot/excanvas.min.js"></script><script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script><script src="http://css3-mediaqueries-js.googlecode.com/svn/trunk/css3-mediaqueries.js"></script><![endif]-->
	<link rel="stylesheet" type="text/css" href="../../css/cloud-admin.css">
	<link rel="stylesheet" type="text/css" href="../../css/themes/default.css" id="skin-switcher">
	<link rel="stylesheet" type="text/css" href="../../css/responsive.css">

	<link href="../../font-awesome/css/font-awesome.min.css" rel="stylesheet">
	<!-- file-input -->
	<link rel="stylesheet" type="text/css" href="../../js/file-input/fileinput.css" />
	<!-- SELECT2 -->
	<link rel="stylesheet" type="text/css" href="../../js/select2/select2.min.css" />
	<!-- UNIFORM -->
	<link rel="stylesheet" type="text/css" href="../../js/uniform/css/uniform.default.min.css" />
	<!-- datatable -->
	<link rel="stylesheet" href="../../js/datatables/datatable.css">
	<!-- WIZARD -->
	<link rel="stylesheet" type="text/css" href="../../js/bootstrap-wizard/wizard.css" />
	<link rel="stylesheet" href="../../js/datepicker/datepicker.css">
	<!-- FONTS
<link href='http://fonts.useso.com/css?family=Open+Sans:300,400,600,700' rel='stylesheet' type='text/css'>
-->
	<!-- JQUERY -->
	<script src="../../js/jquery/jquery-2.0.3.min.js"></script>
	<script src="../../js/common.js"></script>
</head>

<body>
<header class="navbar clearfix" id="header">
</header>

<!-- PAGE -->
<section id="page">
	<!-- SIDEBAR -->
	<div id="sidebar" class="sidebar">
		<div class="sidebar-menu nav-collapse">

			<!-- SIDEBAR MENU -->
			<ul>

			</ul>
			<!-- /SIDEBAR MENU -->
		</div>

	</div>
	<!-- /SIDEBAR -->
	<div id="main-content">

		<div class="container">
			<div class="row">
				<div id="content" class="col-lg-12">
					<!-- PAGE HEADER-->
					<div class="row">
						<div class="col-sm-12">
							<div class="page-header">
								<!-- STYLER -->

								<!-- /STYLER -->
								<!-- BREADCRUMBS -->
								<ul class="breadcrumb">
									<li>
										<i class="fa fa-home"></i>
										<a href="index.html">首页</a>
									</li>
									<li>
										<a href="#">合同管理</a>
									</li>
									<li>进货管理</li>
								</ul>
								<!-- /BREADCRUMBS -->

							</div>
						</div>
					</div>
					<!-- /PAGE HEADER -->
					<!-- SAMPLE -->
					<form id="form_detail">
						<div class="box" style="margin-top:10px">
							<div class="box-title" style="border-bottom:1px solid #5e87b0;line-height:38px">
								<h4><i class="fa fa-file" style="color:red"></i>基本信息</h4>
							</div>
							<div class="box-body">
								<div class="form-group  mrg-bt10">
									<label class="control-label col-md-2 " style="width:100px">供应商：</label>
									<div class="col-md-3 inline" id="supplier_id"></div>
									<label class="control-label col-md-2 " style="width:100px">合同编号：</label>
									<div class="col-md-2 inline" id="contract_code"></div>
									<label class="control-label col-md-2 " style="width:140px">预计到货时间：</label>
									 <div class="col-md-2 inline">
										<div class="col-md-2">
											<div class="col-md-2 inline" id="preSaleDate"></div>
										</div>
										<span class="error-span"></span>
									</div>
									
								</div>
								<div class="form-group  mrg-bt10">
									<label class="control-label col-md-2 " style="width:100px">入库件数：</label>
									<div class="col-md-3 inline" id="total_number"></div>
									<label class="control-label col-md-2 " style="width:140px">入库金额合计：</label>
									<div class="col-md-3 inline" id="total_price"></div>
									
								</div>
								<div class="form-group  mrg-bt10">
									<label class="control-label col-md-2 " style="width:100px">物流公司：</label>
									<div class="col-md-3 inline" id="express_company"></div>
									<label class="control-label col-md-2 " style="width:140px">物流单号：</label>
									<div class="col-md-3 inline" id="logistics_code"></div>
								</div>
								<div class="form-group  mrg-bt10">
									<label class="control-label col-md-2 " style="width:100px">备注：</label>
									<div class="inline" id="remark"></div>
								</div>
								
							</div>
						</div>
						<div class="box" style="margin-top:10px">
						<div class="box-title" style="border-bottom:1px solid #5e87b0;line-height:38px">
											<h4><i class="fa fa-file" style="color:red"></i>进货单明细</h4>
						</div>
						<div class="box-body">
							<div class="form-group  mrg-bt10">
								<table id="db_list" cellpadding="0" cellspacing="0" border="0" class="datatable table table-striped table-bordered table-hover">
												
								</table>
								
							</div>
							
						</div>
						
						</div>

					</form>
					<!-- /SAMPLE -->

					<div class="footer-tools">
								<span class="go-top">
								<i class="fa fa-chevron-up"></i> Top
							</span>
					</div>
				</div>
				<!-- /CONTENT-->
			</div>
		</div>
	</div>
</section>
<!--/PAGE -->
<!-- JAVASCRIPTS -->
<!-- Placed at the end of the document so the pages load faster -->

<!-- BOOTSTRAP -->
<script src="../../bootstrap-dist/js/bootstrap.min.js"></script>

<!-- BLOCK UI -->
<script type="text/javascript" src="../../js/jQuery-BlockUI/jquery.blockUI.min.js"></script>
<!--bootbox-->
<script type="text/javascript" src="../../js/bootbox/bootbox.min.js"></script>
<!-- AUTOSIZE -->
<script type="text/javascript" src="../../js/autosize/jquery.autosize.min.js"></script>
<!-- spinner -->
<script src="../../js/spinner/spin.js"></script>
<!-- DATA TABLES -->
<script type="text/javascript" src="../../js/datatables/bootstrap-select.js"></script>
<script type="text/javascript" src="../../js/datatables/datatable.js"></script>
<script type="text/javascript" src="../../js/datatables/datatable-bootstrap.js"></script>
<script type="text/javascript" src="../../js/datatables/datatable-tabletools.js"></script>
<script type="text/javascript" src="../../js/datatables/fnAddTr.js"></script>
<!-- INPUT MASK -->
<script type="text/javascript" src="../../js/bootstrap-inputmask/bootstrap-inputmask.min.js"></script>

<!-- SELECT2 -->
<script type="text/javascript" src="../../js/select2/select2.min.js"></script>

<!-- UNIFORM -->
<script type="text/javascript" src="../../js/uniform/jquery.uniform.min.js"></script>
<script type="text/javascript" src="../../js/datepicker/datepicker.js"></script>
<script src="../../js/jquery-validate/jquery.validate.min.js"></script>
<!-- COOKIE -->
<script type="text/javascript" src="../../js/jQuery-Cookie/jquery.cookie.min.js"></script>
<!-- CUSTOM SCRIPT -->
<script src="../../js/script.js"></script>

<script src="../../js/Sortable.min.js"></script>
<script>
	var purchaseid = $.getUrlParam("pid");
	var detailpage = function() {
		
		var wizform = $('#form_detail');
		return {
			init: function() {
				App.init();
				$.ajax({
					type: "post",
					url: App.getContextPath()+"admin/purchase/getPurchaseById.do",
					async: true,
					data: {code:purchaseid},
					success: function(result) {
						$("#supplier_id").html(result.data[0].supplier.supplierName);
						$("#contract_code").html(result.data[0].contractCode);
						if(result.data[0].purchaseStatus == "InStock") {
							$("#purchase_status").html("已入库");
						}else if(result.data[0].purchaseStatus == "Settlement"){
							$("#purchase_status").html("结算");
						}
						else{
							$("#purchase_status").html("未入库");
						}
						$("#preSaleDate").html($.getLocalDate(result.data[0].preArriveDate));
						
						//物流信息
						$("#express_company").html(result.data[0].expressCompany);
						$("#logistics_code").html(result.data[0].logisticsCode);
						$("#remark").html(result.data[0].remark);
						
						searchResult(result.data[0].purchaseDetail);
						
						
						var total_price = 0;
						var total_number = 0;
						if(result.data[0].purchaseDetail != null)
						{
							for(var i=0;i<result.data[0].purchaseDetail.length;i++)
							{
								total_price += result.data[0].purchaseDetail[i].inAmount * result.data[0].purchaseDetail[i].price;
								total_number += result.data[0].purchaseDetail[i].inAmount;
							}
						}
						$("#total_price").html(total_price.toFixed(4));
						$("#total_number").html(format_number(total_number));
						
					}
				});
			}
		}
	}();
	
	var searchResult=function(data){
	  var $mainDataTable=null; 
	  /*
	  var url=App.getContextPath()+"admin/purchase/getPurchaseById.do?id="+purchaseid;
	  if($mainDataTable){
		   $mainDataTable.api().ajax.url(url).load();	   		
		   return;	
	   }
	   */
	   var dtSetting = $.dataTableSetting({					
				"serverSide": false,
                "bFilter": false,// 去掉搜索框
                "sScrollX": "100%",
                "sScrollXInner": "100%",
                "bSort": false,
                "paging": false,
                "data": data,		
				"aoColumns" : [ {
					"mDataProp" : "skuCode",
					"sTitle" : "SKU/物料编码",
					"width" : "10%"			
				}, {
					"mDataProp" : "productName",
					"sTitle" : "商品/物料名称",
					"width" : "10%",
				}, {
					"mDataProp" : "color",
					"sTitle" : "颜色",
					"width" : "7%"
				}, {
					"mDataProp" : "sizeName",
					"sTitle" : "规格/大小",
					"width" : "7%"
				}, {
					"sTitle" : "单价",
					"width" : "8%",
					"render":function(data, type, row){
					   return row.price.toFixed(4);
					}
				}, {
					"sTitle" : "进货件数",
					"width" : "8%",
					"render":function(data, type, row){
						return format_number(row.quantity);
					}
				}
				,{
					"sTitle" : "入库件数",
					"width" : "8%",
					"render":function(data, type, row){
						return format_number(row.inAmount);
					}
				}, {
					"sTitle" : "入库金额",
					"width" : "8%",
					"render":function(data, type, row){
					   return (row.inAmount * row.price).toFixed(4);
					}
				}, {
					"sTitle" : "备注",
					"mDataProp" : "remark",
					"width" : "12%"
				}]
			});
		
		  $mainDataTable = $("#db_list").dataTable(dtSetting);
	 };
	 
	$(function() {
		$("#header").load("../head.html");
		detailpage.init();
		$(".go-top").hide();
	});
			 
	
</script>

<!-- /JAVASCRIPTS -->
</body>

</html>